#include<stdio.h>
#include<stdlib.h>
#include<time.h>

bool checkLegalMove( int move,int h[8], int v[8],int x, int y );
bool notVisited( int arr[8][8],int h[8], int v[8], int move,int x, int y );
bool moveRandomly( int arr[8][8],int h[8], int v[8],int move, int moveNo, int *x, int *y );
void printChessBoard( int arr[8][8] ); 
void resetChessBoard( int arr[8][8] ); 

int main(){

	srand( time_t( NULL ) );
	int chessBoard[8][8]= {-1};
	int horizontal[8] = {2,1,-1,-2,-2,-1,1,2};
	int vertical[8] = {-1,-2,-2,-1,1,2,2,1};
	int currentX;
	int currentY;
	int moveNumber;
	int maxMove = 0;


	for(int i=0; i<1000; i++ ){
		moveNumber=0;
		currentX = rand()%8;
		currentY = rand()%8;
		chessBoard[currentX][currentY] = 0;

		while( moveRandomly( chessBoard, horizontal, vertical,rand()%8, moveNumber, &currentX, &currentY)==1)
		{
			moveNumber++;

			if( moveNumber > maxMove )
			{
				maxMove = moveNumber;

				printChessBoard( chessBoard );
			}

		}

		resetChessBoard( chessBoard );

	}
	return 0;

}

void resetChessBoard( int arr[8][8] )
{ 

	for(int i=0; i<8; i++)
	{
		for(int k=0; k<8; k++)
			arr[i][k]=-1;
	}

}
void printChessBoard( int arr[8][8] )
{

	for(int x=0;x<8;x++)
	{
		for(int y=0; y<8; y++)
			printf("%2d", arr[x][y]);
		printf("\n");

	}
	printf("\n--------------\n");
 
}

bool moveRandomly( int arr[8][8], int h[8], int v[8], int move, int moveNo,int *x, int *y);
{
		int ax;
		int ay;
		if(arr[ax][ay]==-1 && (checkLegalMove( rand()%8, h[8], v[8], x, y);==1))
		{
			ax= (*x) + h[move];
			ay= (*y) + v[move];
			moveNo++;
			arr[ax][ay]=moveNo;
		
			return true
		}	
		
			return false
		

bool checkLegalMove( int move,int h[8], int v[8],int x, int y )
{
	int ax;
	int ay;
		
	ax= x + h[move];
	ay= y + v[move];
	if(ax<8 && ax>=0 && ay<8 && ay>=0)
		return true;
	else 
		return false;


}
}
